package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.db.SongListEntity;

import java.util.List;

/**
 * Created by dllo on 15/11/6.
 */
public class CollectListViewAdapter extends BaseAdapter {
    private List<SongListEntity> datas;
    private Context mContext;

    public CollectListViewAdapter(List<SongListEntity> datas, Context mContext) {
        this.datas = datas;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public SongListEntity getItem(int position) {
        return datas != null && datas.size() > 0 ? datas.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.collect_listview_item,null);
            holder.songName = (TextView) convertView.findViewById(R.id.collect_listView_songName);
            holder.authersNames = (TextView) convertView.findViewById(R.id.collect_listView_song_authersNames);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
            SongListEntity songListEntity = getItem(position);
            holder.songName.setText(songListEntity.getTitle());
            holder.authersNames.setText(songListEntity.getAuthor());

        return convertView;
    }

    private class ViewHolder{
        private TextView songName,authersNames;
        private ImageButton imageButton;
    }

}
